package com.longyue.ms.app.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.longyue.ms.app.entity.CarType;
import com.longyue.ms.app.mapper.CarTypeMapper;
import com.longyue.ms.app.service.CarTypeService;
import com.longyue.ms.app.vo.CarTypeParam;
import com.longyue.ms.common.bean.AjaxResult;
import com.longyue.ms.common.bean.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author lishengpeng
 * @Date 2023/1/31 17:53
 */
@Service
public class CarTypeServiceImpl implements CarTypeService {
    @Autowired
    private CarTypeMapper cartypeMapper;

    @Override
    public Pagination<CarType> getPageData(CarTypeParam carTypeParam) throws Exception {
        PageHelper.startPage(carTypeParam.getPageNum(), carTypeParam.getPageSize());
        List<CarType> carTypes = cartypeMapper.selectAll();
        return new Pagination<>(new PageInfo(carTypes));
    }

    @Override
    public AjaxResult addCarType(CarType carType) throws Exception {
        return cartypeMapper.insertSelective(carType) > 0 ? AjaxResult.successResult() : AjaxResult.errorResult("save error");
    }

    @Override
    public AjaxResult deleteById(Integer id) {
        return cartypeMapper.deleteByPrimaryKey(id) > 0 ? AjaxResult.successResult() : AjaxResult.errorResult("delete error");
    }

    @Override
    public AjaxResult updateType(CarType carType) {
        return cartypeMapper.updateByPrimaryKeySelective(carType) > 0 ? AjaxResult.successResult() : AjaxResult.errorResult("update error");
    }

    @Override
    public CarType getById(Integer id) {
        return cartypeMapper.selectByPrimaryKey(id);
    }

}
